package com.wdl.modules.myhouse.utils.util;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 昏昏的君
 */
public class DateUtil {
    private static Date date = new Date();

    public static void main(String[] args) throws InterruptedException {
        startTimer();
        stopTimer("");
    }

    public static void startTimer() {
        date = new Date();
    }

    public static void stopTimer(String mess) throws InterruptedException {
        Thread.sleep(1000);
        Date now = new Date();
        System.out.println(mess+(now.getTime() - date.getTime()) / 60000 + "分钟");
    }

    /**
     * @param start 开始推迟的时间
     * @param num   推迟的时间
     *              从start 推迟 num 天
     **/
    public static Date datePushBackByDays(Date start, int num) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start); //date放到Calender对象中
        calendar.add(Calendar.DATE, num);//后增加n天
        Date result = calendar.getTime();
        return result;
    }

    /**
     * 日期向后推
     *
     * @param start 开始时间
     * @param num   推迟系数
     * @param unit  推迟单位 (Calendar枚举常量)
     * @return
     */
    public static Date datePushBack(Date start, int num, Integer unit) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start); //date放到Calender对象中
        calendar.add(unit, num);//后增加n天
        Date result = calendar.getTime();
        return result;
    }

}
